// 源插件
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import router from 'umi/router';

// 视图插件
import {
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
  Upload,
} from 'antd';

// 外部组件
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

// css OR less预编译器

// 图片

const FormItem = Form.Item;
const { Option } = Select;

/**
 *  Created by xjc on 2019/8/15
 *  Describe:数据连接
 */

@connect(({ fourfunds, loading }) => ({
  fourfunds,
  loading: loading.models.fourfundsRule,
}))
@Form.create()
class StockModal extends PureComponent {
  componentWillMount() {}

  /**
   *  Created by xjc on 2019/8/15
   *  Describe:当前状态
   */

  state = {
    confirmLoading: false,
  };

  onChange = e => {};

  okHandle() {
    const that = this;
    that.setState({
      confirmLoading: true,
    });
    return new Promise((resolve, reject) => {
      setTimeout(resolve, 800);
    })
      .then(() => {
        that.setState({
          confirmLoading: false,
        });
        that.props.form.validateFields((err, values) => {
          if (!err) {
            const { dispatch } = that.props;
            dispatch({
              type: 'fourfunds/MakeTodayInfoByTrade',
              payload: {
                type: parseInt(values.type),
                bankid: values.bankid,
                code: values.code,
                count: values.count,
                price: values.price,
              },
              callback: res => {
                that.props.closeVisbile();
              },
            });
          }
        });
      })
      .catch(() => console.log('Oops errors!'));
  }

  cancelHandle() {
    this.props.closeVisbile();
  }

  render() {
    const { confirmLoading } = this.state;
    const { visible, form, EditORExamine } = this.props;
    const { getFieldDecorator } = form;
    let readOnlyORNot = true;
    if (EditORExamine === 'Edit') {
      readOnlyORNot = false;
    }
    return (
      <Modal
        destroyOnClose
        title="添加"
        visible={visible}
        centered
        onOk={this.okHandle.bind(this)}
        confirmLoading={confirmLoading}
        onCancel={this.cancelHandle.bind(this)}
      >
        <Form onSubmit={this.handleSearch} style={{ overflowY: 'scroll' }}>
          <FormItem label="类型" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('type', {
              initialValue: '0',
            })(
              <Select style={{ width: '85%' }}>
                <Option value="0">买</Option>
                <Option value="1">卖</Option>
              </Select>
            )}
          </FormItem>

          <FormItem label="银行" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('bankid', {
              initialValue: '0',
            })(
              <Select style={{ width: '85%' }}>
                <Option value="0">瑞银</Option>
                <Option value="1">花旗</Option>
                <Option value="2">中银</Option>
              </Select>
            )}
          </FormItem>

          <FormItem label="股票代码" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('code', { initialValue: '' })(
              <Input style={{ width: '85%' }} placeholder="股票代码" />
            )}
          </FormItem>

          <FormItem label="数量" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('count', { initialValue: 0 })(
              <Input style={{ width: '85%' }} placeholder="数量" />
            )}
          </FormItem>

          <FormItem label="价格" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('price', { initialValue: 0 })(
              <Input style={{ width: '85%' }} placeholder="价格" />
            )}
          </FormItem>
        </Form>
      </Modal>
    );
  }

  componentDidMount() {}

  componentWillUnmount() {}
}

export default StockModal;
